#include "displaynum.h"
#include <QDebug>
#include"dbutil.h"
using namespace std;

DisplayNum::DisplayNum(QObject *parent):
 QObject(parent),m_so2(0),m_no(0),m_co(0),m_o2(0){

}
double DisplayNum::getSo2(void){
    return m_so2;
}
double DisplayNum::getNo(void){
    return m_no;
}
double DisplayNum::getCo(void){
    return m_co;
}
double DisplayNum::getO2(void){
    return m_o2;
}
void DisplayNum::setSo2(double so2){
    m_so2=so2;
    emit sendSo2Change();
}
void DisplayNum::setCo(double co){
    m_co=co;
    emit sendCoChange();
}
void DisplayNum::setNo(double no){
    m_no=no;
    emit sendNoChange();
}
void DisplayNum::setO2(double o2){
    m_o2=o2;
    emit sendO2Change();
}
void DisplayNum::getnum(QString num){
    Dbutil db;
    QSqlDatabase data= db.connect();
    QSqlQuery so2dataset;
    QSqlQuery nodataset;
    QSqlQuery codataset;
    QSqlQuery o2dataset;
    string sql_so2data= "select concentration from so2_minute where id="+num.toStdString();
    string sql_nodata="select concentration from nox_minute where id="+num.toStdString();
    string sql_codata="select concentration from co_minute where id="+num.toStdString();
    string sql_o2data= "select concentration from o2_minute where id="+num.toStdString();
    const char *k_so2 = sql_so2data.c_str();
    const char *k_no = sql_nodata.c_str();
    const char *k_co = sql_codata.c_str();
    const char *k_o2 = sql_o2data.c_str();
    bool success_so2 = so2dataset.exec(k_so2);
    bool success_no = nodataset.exec(k_no);
    bool success_co = codataset.exec(k_co);
    bool success_o2 = o2dataset.exec(k_o2);
    if(success_so2&&success_no&&success_co&&success_o2){
       qDebug() << "success num";
       so2dataset.next();
       m_so2=so2dataset.value(0).toDouble();
       setSo2(m_so2);
       nodataset.next();
       m_no=nodataset.value(0).toDouble();
       setNo(m_no);
       codataset.next();
       m_co=codataset.value(0).toDouble();
       setCo(m_co);
       o2dataset.next();
       m_o2=o2dataset.value(0).toDouble();
       setO2(m_o2);
    }


}
